package com.comp6231.replica1.data;

import java.util.Date;

import com.comp6231.replica1.exception.InvalidRecordStatusException;

/**
 * 
 * @author sknarula (narula.sk@gmail.com)
 * @since	September 2013
 * 
 * This is a class which extends class Record and contain additional 
 * missing record related information
 *
 */
public class MissingRecord extends Record {
	
	/**
	 * Attributes specific to Criminal Record
	 */
	public enum MissingStatus {
	    FOUND, MISSING 
	}
	private String lastKnownAddress;
	private Date lastSeenDate;
	private String lastSeenPlace;
	private MissingStatus status;
	
	/**
	 * 
	 * @param fistName
	 * @param lastName
	 * @param lastKnownAddress
	 * @param lastSeenDate
	 * @param lastSeenPlace
	 * @param missingStatus
	 * 
	 * This is an constructor to create a missing record
	 * @throws InvalidRecordStatusException 
	 */
	public MissingRecord(String firstName, String lastName, String lastKnownAddress, 
			Date lastSeenDate, String lastSeenPlace, String missingStatus) throws InvalidRecordStatusException {
		super(firstName, lastName, RecordType.MISSING);
    	this.recordId = "MR" + nextRecordId.getAndIncrement();
    	this.lastKnownAddress = lastKnownAddress;
		this.lastSeenDate = lastSeenDate;
		this.lastSeenPlace = lastSeenPlace;
		this.setStatus(missingStatus);
	}
	
	/**
	 * 
	 * @param fistName
	 * @param lastName
	 * @param lastKnownAddress
	 * @param lastSeenDate
	 * @param lastSeenPlace
	 * @param missingStatus
	 * @throws InvalidRecordStatusException
	 * 
	 * This is an constructor to create a missing record by providing record id
	 *  
	 */
	public MissingRecord(String recordId, String firstName, String lastName, String lastKnownAddress, 
			Date lastSeenDate, String lastSeenPlace, String missingStatus) throws InvalidRecordStatusException {
		super(firstName, lastName, RecordType.MISSING);
    	this.recordId = recordId;
    	this.lastKnownAddress = lastKnownAddress;
		this.lastSeenDate = lastSeenDate;
		this.lastSeenPlace = lastSeenPlace;
		this.setStatus(missingStatus);
	}
	
	/**
	 * Getters and Setters
	 */
	
	public String getLastKnownAddress() {
		return lastKnownAddress;
	}
	
	public void setLastKnownAddress(String lastKnownAddress) {
		this.lastKnownAddress = lastKnownAddress;
	}
	
	public Date getLastSeenDate() {
		return lastSeenDate;
	}
	
	public void setLastSeenDate(Date lastSeenDate) {
		this.lastSeenDate = lastSeenDate;
	}
	
	public String getLastSeenPlace() {
		return lastSeenPlace;
	}
	
	public void setLastSeenPlace(String lastSeenPlace) {
		this.lastSeenPlace = lastSeenPlace;
	}
	
	public MissingStatus getStatus() {
		return status;
	}
	
	public void setStatus(MissingStatus status) {
		this.status = status;
	}
	
	public void setStatus(String newStatus) throws InvalidRecordStatusException {
		try {
			this.status = MissingStatus.valueOf(newStatus);
		}
		catch (IllegalArgumentException e) {
			throw new InvalidRecordStatusException(newStatus + " is not a valid missing status");
		}
		catch (NullPointerException e) {
			throw new InvalidRecordStatusException("Missing status cannot be null");
		}
	}
	
	public String toString() {
		return "Criminal Record [" + this.getRecordId() + ", " + this.getFirstName() + ", " + this.getLastName() + ", " 
				+ this.getLastKnownAddress() + ", " + this.getLastSeenDate() + ", " + this.getLastSeenPlace() + ", " + this.getStatus() + "]";
	}
}
